//
//  WBNavigationController.swift
//  CSWeibo
//
//  Created by 白长松 on 16/6/29.
//  Copyright © 2016年 白长松. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //隐藏默认的导航条
        navigationBar.isHidden = true
        
        setupGoBackButton()
    }

    @objc func popBack() -> () {
        popViewController(animated: true)
    }
    
}

extension WBNavigationController {
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
        
            viewController.hidesBottomBarWhenPushed = true
            let vc = viewController as! WBBaseViewController
            var title = "返回"
            if childViewControllers.count == 1 {
                title = childViewControllers.first?.title ?? "返回"
            }
            
            vc.navItem.leftBarButtonItem = UIBarButtonItem.init(title: title, target: self, action: #selector(popBack), isBack: true)
        }
        
        super.pushViewController(viewController, animated: animated)
    }
    
    func setupGoBackButton() -> () {
        
        
    }
}
